package com.sinopec.pi.scalaguide.function

import java.time.{LocalDate, LocalDateTime}

/**
 * 函数柯里化和偏应用函数
 */
object PartialFunction {
    def log(date: LocalDateTime, message: String) = {
        println(date + "----" + message)
    }
    // 多参数列表（函数柯里化）
    def logMultiParam(date: LocalDateTime)(message: String) = {
        println(date + "----" + message)
    }
    def main(args: Array[String]): Unit = {
        val date = LocalDateTime.now()
        // 产生的偏应用函数
        val logWithDateBound: String => Unit = log(date, _: String)
        // 等价于下面的 log2
        val log2 = logMultiParam(date)_
        logWithDateBound("message1")
        Thread.sleep(1000)
        logWithDateBound("message2")
        Thread.sleep(1000)
        log2("message3")
    }
}
